const app = getApp();
const network = require("../../utils/network.js");
const util = require("../../utils/util.js");
Page({
    /**
     * 页面的初始数据
     */
    data: {},

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        const token = wx.getStorageSync('token')
        if (!!token) {
            util.showLoading('登录中')
            wx.switchTab({
                url: '/pages/workTable/index',
            })
        }
    },

    /**
     * 点击登录按钮
     */
    login(e) {
        util.showLoading('登录中')
        network.POST({
            uri: app.api.doLogin,
            params: {
                username: e.detail.value.username,
                password: e.detail.value.password
            },
            success: (res) => {
                util.hideLoading()
                wx.setStorageSync('token', res.data.token_type + ' ' + res.data.access_token)
                wx.setStorageSync('user_id', res.data.user_id)
                wx.switchTab({
                    url: '/pages/workTable/index',
                })
            }
        }, -1)
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {
    }
})